#ifndef _CSANALYSE_H
#define _CSANALYSE_H

#pragma once

#include <vector>
using namespace std;

struct CS_USERINFO
{
	UINT		m_userId;
	CStringW	m_nickName;
	CS_USERINFO() : m_userId(0)
	{}
};

struct CS_PROC_INFO
{
	DWORD   m_id;
    HANDLE  m_handle;
    DWORD   m_tid;
    HANDLE  m_thandle;
	// added by lr 2005-05-24
	CString m_path;
    CString m_para;
	HANDLE	m_thRdPipe;
	DWORD	m_tidRdPipe;
	// added 2005-06-13
	HANDLE	m_hEvent1;
	HANDLE  m_hEvent2;
};

enum CS_PLAYER_ROLE
{
	CS_ROLE_DEF			= 0,
	CS_ROLE_CT			= 1,
	CS_ROLE_TERRORIST	= 2,
	CS_ROLE_SPECTATOR	= 3,
};

enum CS_GAME_EVENT
{
	CS_GAME_DEF			= 0,
	CS_GAME_ENTER		= 1,
	CS_GAME_JOINROLE	= 2,
	CS_GAME_ROUNDEND	= 3,
	CS_GAME_OUT			= 4,
	CS_GAME_CHANGEMAP	= 5,
	CS_MAP_OVER			= 6,
};

class CCSGamePlayer : public CS_USERINFO
{
public:
	UINT			m_playerId;
	CS_PLAYER_ROLE	m_playerRole;
	CStringW		m_playerCSName;
	UINT			m_killCount;
	UINT			m_bekillCount;
	LONG			m_playTime;
	CCSGamePlayer() : CS_USERINFO(), m_playerId(0), m_playerRole(CS_ROLE_DEF),
		m_killCount(0), m_bekillCount(0), m_playTime(0)
	{}
};

typedef vector<CCSGamePlayer> v_cs_players;

class CCSUserInfoBase
{
public:
	virtual BOOL GetUserInfoByIp(const CString ip, CS_USERINFO &uiUserInfo) = 0;
	virtual void PlayersGaming(const UINT nId, const CString mapName, const UINT nEvent, const v_cs_players &players, const int nCount) = 0;
	virtual UINT GameIndex(const CString gameName, const CString mapName, const UINT nMaxPlayers, const UINT nPort, const CS_PROC_INFO &cpi) = 0;
};

class CCSAnalyseBase
{
public:
	virtual BOOL CreateCSProcess(const TCHAR *chPath, const TCHAR *chParam, 
								  BOOL bSuspend, LPPROCESS_INFORMATION pi) = 0;
	virtual void set_UserInfo(CCSUserInfoBase *pUI) = 0;
	virtual void release() = 0;
};

class CCSAnalyse : public CCSAnalyseBase
{
public:
	BOOL CreateCSProcess(const TCHAR *chPath, const TCHAR *chParam, 
							BOOL bSuspend, LPPROCESS_INFORMATION pi);
	void set_UserInfo(CCSUserInfoBase *pUI);
	void release();
private:
	CCSUserInfoBase *m_pUI; 
};

extern "C"
{
	void DllExport_CSAnalyse(CCSAnalyseBase **pCCS);
}

#endif